package org.finesys.chat.core.base.embedding.filter.logical;

import org.finesys.chat.core.base.embedding.filter.Filter;
import org.finesys.common.core.util.ValidationUtil;

import java.util.Objects;

public class NotFilter implements Filter {

    private final Filter expression;

    public NotFilter(Filter expression) {
        this.expression = ValidationUtil.ensureNotNull(expression, "expression");
    }

    public Filter getExpression() {
        return expression;
    }

    @Override
    public boolean test(Object object) {
        return !this.getExpression().test(object);
    }

    @Override
    public boolean equals(Object object) {
        if (this == object) return true;
        if (object == null || getClass() != object.getClass()) return false;
        NotFilter notFilter = (NotFilter) object;
        return Objects.equals(expression, notFilter.expression);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(expression);
    }
}
